public class test15 {
    class Solution {
        public int largestSumAfterKNegations(int[] nums, int k) {
            Arrays.sort(nums);
            //负的先变正
            for(int i = 0;i<nums.length;i++){
                if(nums[i]<0 && k>0){
                    nums[i] = -nums[i];
                    k--;
                }
            }
            //如果k还有，并为奇数
            if(k>0 && k%2!=0){
                Arrays.sort(nums);
                nums[0] = -nums[0];
            }

            int sum = 0;
            for(int num:nums){
                sum += num;
            }
            return sum;
        }
    }
}
